#include <iostream>

using namespace std;

/*
Question:

find the max square submatix that all grids are filled with 1.

Note: the following algorithm only works for the squre

*/

#define ROW 10  
#define COL ROW  
      
void FindMaxSubSquare(bool M[ROW][COL], int &max_i, int &max_j, int &size)  
{  
    int i,j;  
    int S[ROW][COL];  
       
    /* Set first column of S[][]*/  
    for(i = 0; i < ROW; i++)  
        S[i][0] = M[i][0];  
       
    /* Set first row of S[][]*/  
    for(j = 0; j < COL; j++)  
        S[0][j] = M[0][j];  
       
    /* Construct other entries of S[][]*/  
    for(i = 1; i < ROW; i++)  
    {  
        for(j = 1; j < COL; j++)  
        {  
            if(M[i][j] == 1)  
			{
                S[i][j] = min(S[i][j-1], S[i-1][j]);
				S[i][j] = min(S[i][j], S[i-1][j-1])+ 1;  
			}
            else  
                S[i][j] = 0;  
        }  
    }   
       
    /* Find the maximum entry, and indexes of maximum entry in S[][] */  
    size = S[0][0]; max_i = 0; max_j = 0;  
    for(i = 0; i < ROW; i++)  
    {  
        for(j = 0; j < COL; j++)  
        {  
            if(size < S[i][j])  
            {  
                size = S[i][j];  
                max_i = i;  
                max_j = j;  
            }  
        }  
    }       
    return;
}  

int main()
{
	cout<<"Press any key to terminate..."<<endl;
	return getchar();
}